package cinema;

import java.util.Date;
import java.util.Objects;

public class Schedule {
    private final String scheduleId;
    private Movie movie;
    private Hall hall;
    private Date time;
    private double price;

    public Schedule(String scheduleId, Movie movie, Hall hall, Date time, double price) {
        this.scheduleId = Objects.requireNonNull(scheduleId, "场次ID不能为空");
        this.movie = Objects.requireNonNull(movie, "电影信息不能为空");
        this.hall = Objects.requireNonNull(hall, "影厅信息不能为空");
        this.time = Objects.requireNonNull(time, "放映时间不能为空");
        this.price = validatePrice(price);
    }

    // 获取场次详细信息
    public String getScheduleInfo() {
        return String.format(
                "场次ID: %s | 影片: %s | 影厅: %s | 时间: %s | 价格: %.2f",
                scheduleId, movie.getName(), hall.getHallName(), time, price
        );
    }

    //============ Getter 和 Setter 方法 ============//
    public String getScheduleId() {
        return scheduleId;
    }

    public Movie getMovie() {
        return movie;
    }

    public void setMovie(Movie movie) {
        this.movie = Objects.requireNonNull(movie, "电影信息不能为空");
    }

    public Hall getHall() {
        return hall;
    }

    public void setHall(Hall hall) {
        this.hall = Objects.requireNonNull(hall, "影厅信息不能为空");
    }

    public Date getTime() {
        return new Date(time.getTime()); // 返回副本防止外部修改
    }

    public void setTime(Date time) {
        this.time = Objects.requireNonNull(time, "放映时间不能为空");
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = validatePrice(price);
    }

    //============ 辅助方法 ============//
    private double validatePrice(double price) {
        if (price <= 0) {
            throw new IllegalArgumentException("票价必须大于0");
        }
        return price;
    }

    @Override
    public String toString() {
        return getScheduleInfo();
    }
}